package cn.tedu.javacv159.controller;

import cn.tedu.javacv159.service.ImgStitchingService;
import cn.tedu.javacv159.util.DirectionConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequestMapping("/api/videos")
@Api(tags = "图像拼接")
public class ImgStitchingController {

    @Autowired
    private ImgStitchingService imgStitchingService;

    @PostMapping("/upload")
    @ApiOperation(value = "拼接")
    public ResponseEntity<String> uploadVideo(@RequestPart("file") MultipartFile file,
                                              @RequestParam(value = "intervalTime", defaultValue = "0.5") Double intervalTime,
                                              @RequestParam(value = "direction", defaultValue = DirectionConstant.RIGHT_TO_LEFT) String direction) {
        if (file.isEmpty()) {
            return new ResponseEntity<>("Please select a video file to upload.", HttpStatus.BAD_REQUEST);
        }
        imgStitchingService.handle(file, intervalTime, direction);
        return new ResponseEntity<>("Video handle successfully.", HttpStatus.OK);
    }

}
